package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmDownUpDto;
import com.heima.model.wemedia.dtos.WmNewsAuthDto;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: WmNewsController
 * Description: 自媒体文章相关接口
 * date: 2023/8/8 0008 21:07
 *
 * @author zHan
 */
@RestController
@Slf4j
@RequestMapping("/api/v1/news")
@Api(tags = "自媒体文章相关接口")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 查询文章列表
     *
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("查询文章列表")
    public ResponseResult list(@RequestBody WmNewsPageReqDto dto) {
        return wmNewsService.findList(dto);
    }

    /**
     * 发布文章
     *
     * @param dto
     * @return
     */
    @PostMapping("/submit")
    @ApiOperation("发布文章")
    public ResponseResult submitNews(@RequestBody WmNewsDto dto) {
        return wmNewsService.submitNews(dto);
    }

    /**
     * 查看详情
     *
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    @ApiOperation("查看详情")
    public ResponseResult details(@PathVariable Integer id) {
        return wmNewsService.details(id);
    }


    /**
     * 文章删除
     *
     * @param id
     * @return
     */
    @GetMapping("/del_news/{id}")
    @ApiOperation("文章删除")
    public ResponseResult deleteNews(@PathVariable Integer id) {
        return wmNewsService.deleteNews(id);
    }

    /**
     * 文章上下架
     *
     * @return
     */
    @PostMapping("/down_or_up")
    @ApiOperation("文章上下架")
    public ResponseResult downOrUp(@RequestBody WmDownUpDto dto) {
        return wmNewsService.downOrUp(dto);
    }

    /**
     * 管理端查询文章列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/list_vo")
    @ApiOperation("管理端查询文章列表")
    public ResponseResult listAuth(@RequestBody WmNewsAuthDto dto) {
        return wmNewsService.listAuth(dto);
    }

    /**
     * 管理端查询文章详情
     * @param id
     * @return
     */
    @GetMapping("/one_vo/{id}")
    @ApiOperation("管理端查询文章详情")
    public ResponseResult detailsAuth(@PathVariable Integer id) {
        return wmNewsService.detailsAuth(id);
    }

    /**
     * 文章人工审核成功
     * @param dto
     * @return
     */
    @PostMapping("/auth_pass")
    @ApiOperation("文章人工审核成功")
    public ResponseResult authPass(@RequestBody WmNewsAuthDto dto) {
        return wmNewsService.newsAuthPass(dto);
    }

    /**
     * 文章人工审核失败
     * @param dto
     * @return
     */
    @PostMapping("/auth_fail")
    @ApiOperation("文章人工审核失败")
    public ResponseResult authFail(@RequestBody WmNewsAuthDto dto) {
        return wmNewsService.newsAuthFail(dto);
    }
}
